package com.lyf.scm.admin.domain.remote.allocationservice.facade;


import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.SalesPlanOtherAccuracyDTO;
import com.lyf.scm.admin.api.dto.SalesPlanOtherAccuracyInfoDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.SalesPlanOtherAccuracyRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 * 其他渠道计划_目标与销售计划准确率正面
 *
 * @author: huangtao
 * @data: 2020/7/31
 */
@Service
@Slf4j
public class SalesPlanOtherAccuracyFacade {

    @Resource
    private SalesPlanOtherAccuracyRemote salesPlanOtherAccuracyRemote;

    /**
     * 按条件查询其他渠道计划_目标与销售计划准确率(周)
     * @param salesPlanOtherAccuracy
     * @return
     */
    public PageInfo<SalesPlanOtherAccuracyInfoDTO> listWeekBySelective(SalesPlanOtherAccuracyDTO salesPlanOtherAccuracy) {
        log.info("条件查询其他渠道计划_目标与销售计划准确率(周):salesPlanOtherAccuracy:{}", salesPlanOtherAccuracy);
        Response<PageInfo<SalesPlanOtherAccuracyInfoDTO>> response = salesPlanOtherAccuracyRemote.listWeekBySelective(salesPlanOtherAccuracy);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 查询其他渠道计划_目标与销售计划准确率(范围)
     * @param salesPlanOtherAccuracy
     * @return
     */
    public List<SalesPlanOtherAccuracyInfoDTO> listAllByCycles(SalesPlanOtherAccuracyDTO salesPlanOtherAccuracy) {
        log.info("条件查询其他渠道计划_目标与销售计划准确率(周):salesPlanOtherAccuracy:{}", salesPlanOtherAccuracy);
        Response<List<SalesPlanOtherAccuracyInfoDTO>> response = salesPlanOtherAccuracyRemote.listAllByCycles(salesPlanOtherAccuracy);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 导出
     *
     * @param salesPlanOtherAccuracyDTO
     * @param type
     * @return
     */
    public feign.Response export(SalesPlanOtherAccuracyDTO salesPlanOtherAccuracyDTO,Integer type) {
        log.info("其他渠道计划_目标与销售计划准确率(周)导出:salesPlanOtherAccuracy:{}", salesPlanOtherAccuracyDTO);
        return salesPlanOtherAccuracyRemote.export(salesPlanOtherAccuracyDTO,type);
    }

    public void delete(String opSign) {
        log.info("删除其他渠道计划_目标与销售计划准确率(周):{}", JSON.toJSONString(opSign));
        salesPlanOtherAccuracyRemote.delete(opSign);
    }
}
